<?php

/**
 * 助手函数
 * cighsen02 qq 365182575
 * time：2022.10.26
 * update: 2025.05.09
*/

/**
 * 转成小驼峰 如：third_party => thirdParty  third/party => thirdParty
 *
 * @param string $thing
 * @return string
*/
function camel_case(string $thing): string
{
    return preg_replace_callback_array([
        '#^[a-z]#'      => static fn(array $piece): string => strtolower($piece[0]),
        '#_([a-z])#'    => static fn(array $piece): string => strtoupper($piece[1]),
        '#/([a-z])#'    => static fn(array $piece): string => strtoupper($piece[1])
    ], $thing) ?? $thing;
}

/**
 * 转成大驼峰 如：third_party => ThirdParty  third/party => ThirdParty
 *
 * @param string $thing
 * @return string
*/
function pascal_case(string $thing): string
{
    return preg_replace_callback_array([
        '#^[a-z]#'      => static fn(array $piece): string => strtoupper($piece[0]),
        '#_([a-z])#'    => static fn(array $piece): string => strtoupper($piece[1]),
        '#/([a-z])#'    => static fn(array $piece): string => strtoupper($piece[1])
    ], $thing) ?? $thing;
}
